package com.coderman.infosys.auth.app.facadeimpl.system;

import com.coderman.infosys.auth.domain.enums.errors.SystemErrorEnum;
import com.coderman.infosys.auth.app.convert.SystemConvert;
import com.coderman.infosys.plat.auth.common.dto.PageDTO;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.coderman.infosys.auth.api.dto.system.request.UpdateSystemRequestDTO;
import com.coderman.infosys.auth.api.facade.system.SystemFacade;
import com.coderman.infosys.auth.api.dto.system.SystemDTO;
import org.apache.dubbo.config.annotation.Service;
import java.util.List;
import com.coderman.infosys.auth.domain.bo.system.SystemBO;
import com.coderman.infosys.auth.domain.gataway.SystemModuleQueryGataWay;
import com.coderman.infosys.auth.domain.repository.SystemModuleRepository;


/**
 * @Description:接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class SystemFacadeImpl   implements SystemFacade{

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SystemModuleQueryGataWay systemModuleQueryGataWay;

    @Autowired
    private SystemModuleRepository systemModuleRepository;



    @Override
    public ResultDataDto<SystemDTO> registSystem(SystemDTO systemDTO){
        SystemBO systemBO = SystemConvert.INSTANCE.dto2bo(systemDTO);
        systemModuleRepository.registSystemMeta(systemBO);
        return ResultDataDto.success(systemDTO);
    }



    @Override
    public ResultDataDto<Boolean> updateSystem(UpdateSystemRequestDTO dto){
        SystemBO systemBO = SystemConvert.INSTANCE.dto2bo(dto);
        int intVar = systemModuleRepository.updateSystemMeta(systemBO);
        if(intVar > 0){
            return ResultDataDto.success(true);
        }
        return ResultDataDto.fail(SystemErrorEnum.SYSTEM_UPDATE_ERROR);
    }


    @Override
    public ResultDataDto<SystemDTO> getBySystemCode(String systemCode) {
        SystemBO systemBO = systemModuleQueryGataWay.getSystemByCode(systemCode);
        return ResultDataDto.success(SystemConvert.INSTANCE.bo2dto(systemBO));
    }
}